package model



import scala.collection.mutable.ArrayBuffer

/**
  * author: HuaZhe Ray
  *
  * describe: TODO
  *
  * createDate: 2017/12/7
  * createTime: 18:37
  *
  */
object Repo {
  //使用元组
  def getRepos: Tuple2[List[Student],List[Student]] = {
   /* val lesson1 = new Lesson("语文",95)
    val lesson2 = new Lesson("数学",83)
    val lesson3 = new Lesson("英语",76)*/
//    val students:List[Student] = ArrayLinkedList[Student]

     /**
      * 静态数据，以后从数据库接入
       *
       * 使用样例类，省略 new
      */
    //val student1 =  Student("王一","男",new Lesson("语文",95),new Lesson("数学",65),new Lesson("英语",85))
    val student1 =  Student("王一","男", Lesson("语文",95), Lesson("数学",65), Lesson("英语",85))
    val student2 =  Student("王二","男", Lesson("语文",85), Lesson("数学",85), Lesson("英语",85))
    val student3 =  Student("王三","男", Lesson("语文",55), Lesson("数学",95), Lesson("英语",35))
    val student4 =  Student("王四","男", Lesson("语文",100), Lesson("数学",18), Lesson("英语",97))
    val student5=   Student("王五","男", Lesson("语文",75), Lesson("数学",75), Lesson("英语",75))

    val student6=   Student("张一","女", Lesson("语文",89), Lesson("数学",98), Lesson("英语",100))
    val student7=   Student("张二","男", Lesson("语文",84), Lesson("数学",75), Lesson("英语",98))
    val student8=   Student("张三","女", Lesson("语文",71), Lesson("数学",62), Lesson("英语",74))
    val student9=   Student("张四","男", Lesson("语文",68), Lesson("数学",91), Lesson("英语",62))
    val student10=  Student("张武","女", Lesson("语文",99), Lesson("数学",100), Lesson("英语",78))


    val student11=   Student("李一","男", Lesson("语文",41), Lesson("数学",87), Lesson("英语",65))
    val student12=   Student("李二","女", Lesson("语文",96), Lesson("数学",71), Lesson("英语",89))
    val student13=   Student("李三","男", Lesson("语文",54), Lesson("数学",72), Lesson("英语",100))
    val student14=   Student("李四","女", Lesson("语文",63), Lesson("数学",32), Lesson("英语",89))
    val student15=   Student("刘一","女", Lesson("语文",63), Lesson("数学",32), Lesson("英语",89))

    val student16=   Student("刘二","男", Lesson("语文",41), Lesson("数学",87), Lesson("英语",65))
    val student17=   Student("刘三","女", Lesson("语文",96), Lesson("数学",71), Lesson("英语",89))
    val student18=   Student("刘四","男", Lesson("语文",54), Lesson("数学",72), Lesson("英语",54))
    val student19=   Student("刘五","女", Lesson("语文",63), Lesson("数学",32), Lesson("英语",89))
    val student20=   Student("刘六","女", Lesson("语文",63), Lesson("数学",32), Lesson("英语",89))


    val arrayA =  ArrayBuffer[Student]()
    arrayA += (student1,student2,student3,student4,student5)
    arrayA += (student6,student7,student8,student9,student10)
    val listA = arrayA.toList

    val arrayB =  ArrayBuffer[Student]()
    arrayB += (student11,student12,student13,student14,student15)
    arrayB += (student16,student17,student18,student19,student20)
    arrayB.toList
    val listB = arrayB.toList

    return (listA,listB)

  }


    val classOne =  Classes("三年一班",getRepos._1)

    val classTwo =  Classes("三年二班",getRepos._2)

    val grades:List[Classes] = List(classOne,classTwo)



    def getGrades(): Grade ={
        val grade =  Grade("初三",grades)
        grade
    }

   /**
    * 根据每个班,根据传入值，获取各门课程
    */
    def getLesson(clas: Classes,lesson: Lesson): List[Lesson] = {

      val students = clas.students

      val lessons =  for{
        s <- students
      } yield lesson.name match {
        case "语文" => s.chinese
        case "数学" => s.math
        case "英语" => s.english
      }

      lessons
    }

  /**
    * 更好的写法  列表 -> 列表
    * @param clas
    * @param lesson
    * @return
    */
  def getLesson1(clas: Classes,lesson: Lesson): List[Lesson] = {

        clas.students.map(students =>{
            lesson.name match {
              case "语文" => students.chinese
              case "数学" => students.math
              case "英语" => students.english
            }

        })
  }


}
